package logic

import (
	"gorm.io/gorm"
	"web-app/web-server/internal/context"
	"web-app/web-server/internal/dao"
	"web-app/web-server/internal/dao/model"
	"web-app/web-server/internal/dto"
)

type UserLogic struct {
	db *gorm.DB
}

func NewUserLogic(ctx *context.Context) *UserLogic {
	return &UserLogic{
		db: dao.GetDao(ctx.Config.DB),
	}
}

func (ul *UserLogic) Login(username string, password string) (*dto.Result, error) {
	user := new(model.User)
	ul.db.Model(user).Where("username = ? and password = ?", username, password).First(user)
	return &dto.Result{
		Code: 200,
		Data: user,
	}, nil
}
